﻿using System;
using System.Web;
using System.Web.Caching;

namespace cms.libs.Utility
{
    public class CachingUtility
    {
        #region --- Khai báo tên các session ---

        public const string CacheAccount = "EbankAccount";
        public const string CurrentGameId = "CurrentGameId";

        #endregion

        /// <summary>
        /// lấy ra giá trị session
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public object GetValue(string name)
        {
            return HttpRuntime.Cache.Get(name.Trim().ToLower());
        }

        /// <summary>
        /// hủy một session
        /// </summary>
        /// <param name="name"></param>
        public void Remove(string name)
        {
            HttpRuntime.Cache.Remove(name.Trim().ToLower());
        }


        /// <summary>
        /// Nạp giá trị cho session
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public void SetValue(string name, object value)
        {
            //HttpRuntime.Cache.Insert(name.Trim().ToLower(), value, null, DateTime.Now.AddDays(20), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
            HttpRuntime.Cache.Insert(name.Trim().ToLower(), value, null, DateTime.Now.AddMinutes(10), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
        }

        public void SetValueWithTime(string name, object value, int minutes)
        {
            HttpRuntime.Cache.Insert(name.Trim().ToLower(), value, null, DateTime.Now.AddMinutes(minutes), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
        }

        public void SetValueWithSeconds(string name, object value, int seconds)
        {
            HttpRuntime.Cache.Insert(name.Trim().ToLower(), value, null, DateTime.Now.AddSeconds(seconds), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
        }

    }
}
